package com.wang.springbootinit.controller.student;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.springbootinit.common.BaseResponse;
import com.wang.springbootinit.common.ResultUtils;
import com.wang.springbootinit.model.dto.answer.SubmitAnswerRequest;
import com.wang.springbootinit.model.entity.Question;
import com.wang.springbootinit.model.vo.QuestionVO;
import com.wang.springbootinit.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 统考题目管理
 */
@RestController
@RequestMapping("/student/examination/question")
public class StudentQuestionController {

    @Autowired
    private QuestionService questionService;

    /**
     * 根据章节ID查询题目列表
     * @param chapterId 章节ID
     * @param questionType 题目类型（选填）
     * @param questionCategory 题目分类（选填）
     */
    @GetMapping("/list")
    public BaseResponse<List<Question>> getQuestionList(
            @RequestParam Long chapterId,
            @RequestParam(required = false) Integer questionType,
            @RequestParam(required = false) Integer questionCategory) {
        return ResultUtils.success(questionService.getQuestionsByChapter(chapterId, questionType, questionCategory));
    }

    /**
     * 做题训练列表-根据章节ID查询题目列表（分页）
     * @param chapterId 章节ID
     * @param questionType 题目类型（选填）
     * @param questionCategory 题目分类（选填）
     * @param current 当前页码
     * @param pageSize 每页数量
     */
    @GetMapping("/page")
    public BaseResponse<Page<QuestionVO>> getQuestionPage(
            @RequestParam Long chapterId,
            @RequestParam(required = false) Integer questionType,
            @RequestParam(required = false) Integer questionCategory,
            @RequestParam(defaultValue = "1") long current,
            @RequestParam(defaultValue = "10") long pageSize,HttpServletRequest request) {
        return ResultUtils.success(questionService.getQuestionsByChapterPage(chapterId, questionType, questionCategory, current, pageSize,request));
    }

    /**
     * 提交章节练习答案
     * @param submitAnswerRequest 答案请求
     * @return 提交结果
     */
    @PostMapping("/submit")
    public BaseResponse<Boolean> submitAnswers(@RequestBody SubmitAnswerRequest submitAnswerRequest, HttpServletRequest request) {
        return ResultUtils.success(questionService.submitAnswers(submitAnswerRequest,request));
    }

}
